rawset(_G, "CV_Rampage", {})
local R = CV_Rampage

CV_Rampage.muties = CV_RegisterVar({
	name = "mutator",
	defaultvalue = "Default",
	PossibleValue = {Default = -1, None = 0, RocketArena = 1, Instagib = 2, CQC = 3, SWAT = 4},
	flags = CV_NETVAR,
})

addHook("PlayerThink", function(player)
	if	R.muties.value == 1 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == "Rocket")
		//player.powers[pw_shield] = SH_NONE
		//player.ringweapons = 16
		//player.rings = 0
		//player.powers[pw_infinityring] = 0
		//player.powers[pw_automaticring] = 0
		//player.powers[pw_bouncering] = 0
		//player.powers[pw_scatterring] = 0
		//player.powers[pw_grenadering] = 0
		//player.powers[pw_railring] = 0
		//player.powers[pw_explosionring] = 999
		//player.ammoremovaltimer = 0
		//if player.weapondelay > 35	then
		//	player.weapondelay = 35
		//end
	elseif R.muties.value == 2 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 2)
		//player.powers[pw_shield] = SH_NONE
		//player.ringweapons = 32
		//player.powers[pw_infinityring] = 0
		//player.powers[pw_automaticring] = 0
		//player.powers[pw_bouncering] = 0
		//player.powers[pw_scatterring] = 0
		//player.powers[pw_grenadering] = 0
		//player.powers[pw_railring] = 999
		//player.powers[pw_explosionring] = 0
		//player.ammoremovaltimer = 0
		//if player.weapondelay > 35	then
		//	player.weapondelay = 35
		//end
		player.ammolist = {
			[1] = 0,
			[2] = 0,
			[3] = 0,
			[4] = 600,
		}
		player.rfwattack = $*69
/*	elseif R.muties.value == 3 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 3)
		player.powers[pw_shield] = SH_NONE
		player.rings = 0
		print(tostring(player.ringweapons)) */
	elseif R.muties.value == 4 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 4)
		player.rfwdefense = $/4
		//player.charability2 = CA2_NONE
		//player.ringweapons = 7
		//player.powers[pw_grenadering] = 0
		//player.powers[pw_railring] = 0
		//player.powers[pw_explosionring] = 0
	end
end)

addHook("PlayerSpawn", function(p)
	if (not (gametyperules & GTR_CAMPAIGN)) or (mapheaderinfo[gamemap].pistolstart and (string.lower(mapheaderinfo[gamemap].pistolstart) == "true" or string.lower(mapheaderinfo[gamemap].pistolstart) == "on" or mapheaderinfo[gamemap].pistolstart == "1")) then
		//print("fart")
		p.mutatorsinitialized = false
	end
end)

/*addHook("MapLoad", function(p)
	if (not (gametyperules & GTR_CAMPAIGN)) or (mapheaderinfo[gamemap].pistolstart and (string.lower(mapheaderinfo[gamemap].pistolstart) == "true" or string.lower(mapheaderinfo[gamemap].pistolstart) == "on" or mapheaderinfo[gamemap].pistolstart == "1")) then
		//print("fart")
		for p in players.iterate do
			p.mutatorsinitialized = false
		end
	end
end)*/

addHook("PlayerThink", function(player)
	if player.spectator or player.playerstate == PST_DEAD then
		player.mutatorsinitialized = false
	end
	if (not player.mutatorsinitialized) and (not player.spectator) then
		if R.muties.value == 1 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 1)
			player.weaponslist = {
				[1] = {},
				[2] = {},
				[3] = {},
				[4] = {},
				[5] = {},
				[6] = {},
				[7] = {},
				[8] = {},
				[9] = {},
				[10] = {},
			}
			player.ammolist = {
				[1] = 0,
				[2] = 0,
				[3] = 100,
				[4] = 0,
			}
			RFW.GivePlayerWeapon(player, 5, RFW.WP_rocketlauncher)
			player.slot = 5
			player.weapon = RFW.WP_rocketlauncher
			player.phealth = 200
			player.parmor = 200
			player.papval = 50
			player.mutatorsinitialized = true
		elseif R.muties.value == 2 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 2)
			player.weaponslist = {
				[1] = {},
				[2] = {},
				[3] = {},
				[4] = {},
				[5] = {},
				[6] = {},
				[7] = {},
				[8] = {},
				[9] = {},
				[10] = {},
			}
			player.ammolist = {
				[1] = 0,
				[2] = 0,
				[3] = 0,
				[4] = 600,
			}
			RFW.GivePlayerWeapon(player, 6, RFW.WP_railgun)
			player.slot = 6
			player.weapon = RFW.WP_railgun
			player.mutatorsinitialized = true
		elseif R.muties.value == 3 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 3)
			//player.rings = 200
			//player.ringweapons = 63
			//player.powers[pw_infinityring] = 800
			//player.powers[pw_automaticring] = 400
			//player.powers[pw_bouncering] = 100
			//player.powers[pw_scatterring] = 50
			//player.powers[pw_grenadering] = 100
			//player.powers[pw_railring] = 50
			//player.powers[pw_explosionring] = 50
			player.weaponslist = {
				[1] = {},
				[2] = {},
				[3] = {},
				[4] = {},
				[5] = {},
				[6] = {},
				[7] = {},
				[8] = {},
				[9] = {},
				[10] = {},
			}
			player.ammolist = {
				[1] = 0,
				[2] = 0,
				[3] = 0,
				[4] = 0,
			}
			RFW.GivePlayerWeapon(player, 1, RFW.WP_axe)
			player.slot = 1
			player.weapon = RFW.WP_axe
			player.mutatorsinitialized = true
		/*elseif R.muties.value == 3 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 4)
			player.rings = 200
			player.powers[pw_shield] = SH_ATTRACT
			P_SpawnShieldOrb(player)
			player.powers[pw_infinityring] = 800
			player.powers[pw_automaticring] = 100
			player.powers[pw_bouncering] = 20
			player.powers[pw_scatterring] = 50*/
		elseif R.muties.value == 4 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 4)
			//player.rings = 200
			//player.ringweapons = 63
			//player.powers[pw_infinityring] = 800
			//player.powers[pw_automaticring] = 400
			//player.powers[pw_bouncering] = 100
			//player.powers[pw_scatterring] = 50
			//player.powers[pw_grenadering] = 100
			//player.powers[pw_railring] = 50
			//player.powers[pw_explosionring] = 50
			player.weaponslist = {
				[1] = {},
				[2] = {},
				[3] = {},
				[4] = {},
				[5] = {},
				[6] = {},
				[7] = {},
				[8] = {},
				[9] = {},
				[10] = {},
			}
			player.ammolist = {
				[1] = 50,
				[2] = 0,
				[3] = 0,
				[4] = 0,
			}
			RFW.GivePlayerWeapon(player, 1, RFW.WP_knife)
			RFW.GivePlayerWeapon(player, 2, RFW.WP_pistol)
			RFW.GivePlayerWeapon(player, 3, RFW.WP_shotgun)
			player.slot = 3
			player.weapon = RFW.WP_shotgun
			player.mutatorsinitialized = true
		/*elseif R.muties.value == 3 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 4)
			player.rings = 200
			player.powers[pw_shield] = SH_ATTRACT
			P_SpawnShieldOrb(player)
			player.powers[pw_infinityring] = 800
			player.powers[pw_automaticring] = 100
			player.powers[pw_bouncering] = 20
			player.powers[pw_scatterring] = 50*/
		else
			player.mutatorsinitialized = true
		end
	end
end)

/*RFW.MutieWeaponPickupTable = { //to look up item pickups we should delete cause they cant just hAVE THEIR OWN FUCKING FLAG FUCK FUCK
	[MT_PISTOL] = true,
	[MT_SHOTGUN] = true,
	[MT_KARASAWA] = true,
	[MT_CHAINGUN] = true,
	[MT_GRENADELAUNCHER] = true,
	[MT_ROCKETLAUNCHER] = true,
	[MT_RAILGUN] = true,
	[MT_AXE] = true,
	[MT_PLASMAGUN] = true,
}

RFW.MutieAmmoPickupTable = { //to look up item pickups we should delete cause they cant just hAVE THEIR OWN FUCKING FLAG FUCK FUCK
	[MT_PISTOL] = true,
	[MT_SHOTGUN] = true,
	[MT_KARASAWA] = true,
	[MT_CHAINGUN] = true,
	[MT_GRENADELAUNCHER] = true,
	[MT_ROCKETLAUNCHER] = true,
	[MT_RAILGUN] = true,
	[MT_AXE] = true,
	[MT_PLASMAGUN] = true,
}*/

RFW.Mutie_CQCPickupTable = { //to look up item pickups we should delete cause they cant just hAVE THEIR OWN FUCKING FLAG FUCK FUCK
	[MT_SHOTGUN] = true,
	[MT_AXE] = true,
}

//ammopickup

addHook("MapLoad", function()
	if R.muties.value == 1 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 1) then
		for mo in mobjs.iterate() do
			//if mo.player then continue end
			//if mo.flags & MF_SCENERY then continue end
			//if mo.flags & MF_NOTHINK then continue end
			if mo.info.ammopickup then
				if mo.type == MT_ROCKET or mo.type == MT_ROCKET_BOX then
					continue
				elseif mo.type == MT_BULLET_BOX or mo.type == MT_SHELL_BOX or mo.type == MT_PLASMA_BOX then
					P_SpawnMobjFromMobj(mo, 0, 0, 0, MT_ROCKET_BOX)
					P_RemoveMobj(mo)
					continue
				else
					P_SpawnMobjFromMobj(mo, 0, 0, 0, MT_ROCKET)
					P_RemoveMobj(mo)
					continue
				end
			end
			if mo.info.weaponpickup then
				//mo.flags2 = $|MF2_DONTRESPAWN
				P_RemoveMobj(mo)
				continue
			end
		end
	elseif R.muties.value == 2 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 2) then
		for mo in mobjs.iterate() do
			//if mo.player then continue end
			//if mo.flags & MF_SCENERY then continue end
			//if mo.flags & MF_NOTHINK then continue end
			if mo.info.ammopickup then
				//mo.flags2 = $|MF2_DONTRESPAWN
				P_RemoveMobj(mo)
				continue
			end
			if mo.info.weaponpickup then
				//mo.flags2 = $|MF2_DONTRESPAWN
				P_RemoveMobj(mo)
				continue
			end
		end
	elseif R.muties.value == 3 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 3) then
		for mo in mobjs.iterate() do
			//if mo.player then continue end
			//if mo.flags & MF_SCENERY then continue end
			//if mo.flags & MF_NOTHINK then continue end
			if mo.info.ammopickup then
				if mo.type == MT_SHELLS or mo.type == MT_SHELL_BOX then
					continue
				elseif mo.type == MT_BULLET_BOX or mo.type == MT_ROCKET_BOX or mo.type == MT_PLASMA_BOX then
					P_SpawnMobjFromMobj(mo, 0, 0, 0, MT_SHELL_BOX)
					P_RemoveMobj(mo)
					continue
				else
					P_SpawnMobjFromMobj(mo, 0, 0, 0, MT_SHELLS)
					P_RemoveMobj(mo)
					continue
				end
			end
			if mo.info.weaponpickup and (not RFW.Mutie_CQCPickupTable[mo.type]) then
				//mo.flags2 = $|MF2_DONTRESPAWN
				P_RemoveMobj(mo)
				continue
			end
		end
	elseif R.muties.value == 4 or (R.muties.value == -1 and mapheaderinfo[gamemap].mapmutator == 4) then
		for mo in mobjs.iterate() do
			//if mo.player then continue end
			//if mo.flags & MF_SCENERY then continue end
			//if mo.flags & MF_NOTHINK then continue end
			if mo.info.ammopickup then
				if mo.type == MT_SHELLS or mo.type == MT_SHELL_BOX or mo.type == MT_BULLET_BOX or mo.type == MT_BULLETs then
					continue
				else
					P_RemoveMobj(mo)
					continue
				end
			end
			if mo.info.weaponpickup then
				//mo.flags2 = $|MF2_DONTRESPAWN
				P_RemoveMobj(mo)
				continue
			end
		end
	end
end)